package com.workshop.web;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.base.commom.ResponseUtils;
import com.workshop.entity.SysUser;
import com.workshop.service.ISysUserService;
import com.workshop.utils.ResultMsg;
import com.workshop.utils.check.CheckUtil;
import com.workshop.utils.session.SessionManager;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengluqiang
 * @since 2019-04-13
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
	
	@Resource
	private ISysUserService sysUserService;
	
	@PostMapping("/loginSubmit")
	public Map<String, Object> loginSubmit(HttpServletRequest request,String username, String password){
		return sysUserService.loginSubmit(request,username,password);
	}
	
	@PostMapping("/getSysNameAndImg")
	public Map<String,Object> getSysNameAndImg(HttpServletRequest request) throws Exception{
		SysUser sysUser = (SysUser) CheckUtil.checkOline(request);
		Map<String,Object> map = new HashMap<>();
		map.put("userName", sysUser.getUsername());
		map.put("nickName", sysUser.getNickname());
//		map.put("headImg", sysUser.getUsername());
		return ResponseUtils.success(map);
	}
	
	@PostMapping("/logout")
	public Map<String, Object> logout(HttpServletRequest request){
		SessionManager sessionManager = SessionManager.getInstance();
		sessionManager.delSession(request.getSession());
		return ResponseUtils.success("退出成功！");
	}
	
}

